import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:intl/intl.dart';
import 'package:kq_flutter_widgets/resources/kq_theme_colors.dart';
import 'package:kq_flutter_widgets/special/ImmTemperatureView/imm_temperature_view.dart';
import 'package:kq_flutter_widgets/special/progressForScienceTestMoldEvaluate/simple_science_test_mold_evaluate_view.dart';
import 'package:kq_flutter_widgets/special/seekBarForScienceTestMold/seek_bar_for_science_test_mold_result.dart';
import 'package:kq_flutter_widgets/special/seekBarForScienceTestMold/simple_science_test_mold_edit.dart';
import 'package:kq_flutter_widgets/special/seekBarForScienceTestMold/simple_science_test_mold_result.dart';
import 'package:kq_flutter_widgets/special/seekBarForScienceTestMold/simple_science_test_mold_view_util.dart';
import 'package:kq_flutter_widgets/special/progressForScienceTestMoldEvaluate/progress_for_science_test_mold_evaluate.dart';
import 'package:kq_flutter_core_widget/utils/log.dart';
import 'package:kq_flutter_widgets/widgets/formItem/entity/kq_form_entity.dart';
import 'package:kq_flutter_widgets/widgets/formItem/kq_header_item_view.dart';
import 'package:kq_flutter_widgets/widgets/tabView/kq_tab_view.dart';
import 'package:kq_flutter_widgets/widgets/titleBar/kq_title_bar.dart';

import '../../resources/Images.dart';
import '../../resources/kq_images.dart';

/// @author 高裕
/// 特殊定制控件
class SpecialOrderDemo extends StatefulWidget {
  const SpecialOrderDemo({super.key});

  @override
  State<SpecialOrderDemo> createState() => SpecialOrderDemoState();
}

class SpecialOrderDemoState extends State<SpecialOrderDemo> {
  final numberFormat = NumberFormat("#.##");
  List<NormalSimpleScienceTestMoldEditEntity>? editList;
  List<NormalSimpleScienceTestMoldResultEntity>? resultList;

  @override
  void initState() {
    super.initState();
    double? scienceValue = 55.32;
    editList = [
      NormalSimpleScienceTestMoldEditEntity(
        max: 72.47,
        min: 32.15,
        value: scienceValue,
        pointColor: KqThemeColors.textRed,
        paramPic: KqImages.taskIcZhuangtai12Black,
        paramTitle: "机筒温度(°C)",
        paramTips: "结果1 = 机筒温度(°C) * 2 , 结果2 = 机筒温度(°C) / 2",
        customRightView: (value, entity) {
          return Text(
            value == null ? '' : numberFormat.format(value),
            style: TextStyle(
                color: (value! <= entity.max! && value >= entity.min!)
                    ? KqThemeColors.text26
                    : KqThemeColors.textRed,
                fontSize: 20.sp),
          );
        },
        onMove: (value, entity) {
          Log.d(value.toString(), tag: 'seek');
          resultList?[0].value = value == null ? null : (value * 2);
          resultList?[0].state?.update();
        },
        onMoveEnd: (value, entity) {
          Log.d(value.toString(), tag: 'seek');
          resultList?[1].value = value == null ? null : (value / 2);
          resultList?[1].state?.update();
        },
        onTextChange: (value, entity) {
          Log.d(value.toString(), tag: 'seek');
          resultList?[0].value = value == null ? null : (value * 2);
          resultList?[0].state?.update();
          resultList?[1].value = value == null ? null : (value / 2);
          resultList?[1].state?.update();
        },
      ),
    ];
    resultList = [
      NormalSimpleScienceTestMoldResultEntity(
        max: 72.47,
        min: 32.15,
        imagePath: KqImages.taskIcKehu12Black,
        title: '结果1',
        value: scienceValue * 2,
      ),
      NormalSimpleScienceTestMoldResultEntity(
        max: 72.47,
        min: 32.15,
        imagePath: KqImages.taskIcKehu12Black,
        title: '结果2',
        value: scienceValue / 2,
      ),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: KqHeadBar(
        headTitle: '特殊定制控件',
        back: () {
          Get.back();
        },
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            KqHeaderItemView(entity: KqFormEntity(title: '科学试模滑块')),
            Column(
              children: [
                ...SimpleScienceTestMoldViewUtil
                    .createSimpleScienceTestMoldEditList<
                    NormalSimpleScienceTestMoldEditEntity>(editList!),
                ...SimpleScienceTestMoldViewUtil
                    .createSimpleScienceTestMoldResultList<
                    NormalSimpleScienceTestMoldResultEntity>(resultList!),
                KqTabView(
                    titles: const ['清空'],
                    colorTypes: const [ColorType.lineGrey],
                    tabIndexBlock: (index, disable) {
                      if (index == 0) {
                        SimpleScienceTestMoldViewUtil
                            .clearAllSimpleScienceTestMoldView(
                            editList!, resultList!);
                      }
                    }),
              ],
            ),
            KqHeaderItemView(entity: KqFormEntity(title: '科学试模评价进度条')),
            const SimpleScienceTestMoldEvaluateView(
              title: '生产能耗',
              gradientColor: [
                Color(0xFF34C759),
                Color(0xFFFFEF09),
                Color(0xFFFF453A),
              ],
              cutPart: 5,
              progress: 100,
            ),
            const SimpleScienceTestMoldEvaluateView(
              title: '设备损耗',
              gradientColor: [
                Color(0xFF02FDFE),
                Color(0xFF006B6B),
              ],
              cutPart: 3,
              progress: 12,
            ),
            const SimpleScienceTestMoldEvaluateView(
              title: '模具损耗',
              gradientColor: [
                Color(0xFF02FDFE),
                Color(0xFF006B6B),
              ],
              cutPart: 3,
              progress: null,
            ),
            KqHeaderItemView(entity: KqFormEntity(title: '注塑机多段温度')),
            Container(
              padding: EdgeInsets.symmetric(horizontal: 16.r),
              child: const ImmTemperatureView(data: '117,128,188,-,233'),
            ),
          ],
        ),
      ),
    );
  }
}
